home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / pcl4c60.zip / XONOFF.C < prev    next >
Text File  |  1996-10-10  |  1KB  |  50 lines

  1. /*
  2. **   XONOFF.C
  3. **
  4. **   1. XON/XOFF protocol can NOT be used with binary data.
  5. **   2. Before using XioPutc() and XioGetc(), call XioSetup() with
  6. **      LoWater = 16, and HiWater = RX_QUEUE_SIZE - 16, where
  7. **      RX_QUEUE_SIZE is the queue size passed in SioRxBuf().
  8. **   3. After calling XioSetup(), call XioPutc() and XioGetc()
  9. **      instead of SioPutc() and SioGetc().
  10. */
  11.  
  12. #include "pcl4c.h"
  13. #include "xonoff.h"
  14.  
  15. #define XON  0x11
  16. #define XOFF 0x13
  17.  
  18. static char LastXsent = XON;
  19. static char LastXreceived = XON;
  20. static int  RxHiWater = 48;
  21. static int  RxLoWater = 16;
  22.  
  23. void XioSetup(int LoWater,int HiWater)
  24. {RxLoWater = LoWater;
  25.  RxHiWater = HiWater;
  26.  LastXsent = XON;
  27.  LastXreceived = XON;
  28. }
  29.  
  30. int XioPutc(int Port,char C)
  31. {if(LastXreceived==XOFF) return -1;
  32.  return SioPutc(Port,C);
  33. }
  34.  
  35. int XioGetc(int Port)
  36. {int C;
  37.  C = SioGetc(Port,0);
  38.  if((C==XON)||(C==XOFF)) LastXreceived = C;
  39.  else switch(LastXsent)
  40.    {case XOFF:
  41.       if(SioRxQue(Port)<=RxLoWater) SioPutc(Port,LastXsent=XON);
  42.       break;
  43.     case XON:
  44.       if(SioRxQue(Port)>=RxHiWater) SioPutc(Port,LastXsent=XOFF);
  45.       break;
  46.    }
  47.  return C;
  48. }
  49.  
  50.